aboutsummaryrefslogtreecommitdiff
path: root/src/aoemotebutton.cpp
diff options
context:
space:
mode:
authorSalanto <62221668+Salanto@users.noreply.github.com>2024-05-18 03:33:43 +0200
committerGitHub <noreply@github.com>2024-05-18 03:33:43 +0200
commit51338e30e046f1a62c84049b34577f0f3b5db6e3 (patch)
tree283c95f8f776ed852d03a816388695afd65c0f73 /src/aoemotebutton.cpp
parent469e293a1885e49f1d5994d41ac7cfc9f4666952 (diff)
parentf9c7205210fb9f768f583065971ece09e6b5eb03 (diff)
Merge pull request #957 from AttorneyOnline/kaleidoscope
The Kaleidoscope - Hell, it's about time.
Diffstat (limited to 'src/aoemotebutton.cpp')
-rw-r--r--src/aoemotebutton.cpp93
1 files changed, 47 insertions, 46 deletions
diff --git a/src/aoemotebutton.cpp b/src/aoemotebutton.cpp
index c0539844..028c265d 100644
--- a/src/aoemotebutton.cpp
+++ b/src/aoemotebutton.cpp
@@ -1,78 +1,79 @@
#include "aoemotebutton.h"
+
#include "file_functions.h"
-AOEmoteButton::AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app,
- int p_x, int p_y, int p_w, int p_h)
- : QPushButton(p_parent)
-{
- parent = p_parent;
- ao_app = p_ao_app;
+#include <QDebug>
- this->move(p_x, p_y);
- this->resize(p_w, p_h);
+AOEmoteButton::AOEmoteButton(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 QLabel(this);
- ui_selected->resize(size());
ui_selected->setAttribute(Qt::WA_TransparentForMouseEvents);
+ ui_selected->resize(width, height);
ui_selected->hide();
- connect(this, &AOEmoteButton::clicked, this, &AOEmoteButton::on_clicked);
+ connect(this, &AOEmoteButton::clicked, this, [this] { Q_EMIT emoteClicked(m_id); });
}
-void AOEmoteButton::set_selected_image(QString p_image)
+void AOEmoteButton::setSelectedImage(QString p_image)
{
- if (file_exists(p_image)) {
+ if (file_exists(p_image))
+ {
ui_selected->setStyleSheet("border-image: url(\"" + p_image + "\")");
}
- else {
+ else
+ {
ui_selected->setStyleSheet("background-color: rgba(0, 0, 0, 128)");
}
}
-void AOEmoteButton::set_image(QString p_image, QString p_emote_comment)
+int AOEmoteButton::id()
{
- QString tmp_p_image = p_image;
-
- if (file_exists(p_image)) {
- this->setText("");
- this->setStyleSheet(
- "QPushButton { border: none; }"
- "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }");
- this->setIcon(QPixmap(p_image).scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
- this->setIconSize(this->size());
- }
- else {
- this->setText(p_emote_comment);
- this->setStyleSheet("QPushButton { border-image: url(); }"
- "QToolTip { background-image: url(); color: #000000; "
- "background-color: #ffffff; border: 0px; }");
- this->setIcon(QIcon());
- this->setIconSize(this->size());
- }
+ return m_id;
}
-void AOEmoteButton::set_char_image(QString p_char, int p_emote, bool on)
+void AOEmoteButton::setImage(QString character, int emoteId, bool enabled)
{
- QString emotion_number = QString::number(p_emote + 1);
- QStringList suffixes { "_off", "_on" };
+ QString emotion_number = QString::number(emoteId + 1);
+
QStringList suffixedPaths;
- for (const QString &suffix : suffixes) {
- suffixedPaths.append(ao_app->get_image_suffix(ao_app->get_character_path(
- p_char, "emotions/button" + emotion_number + suffix)));
+ static const QStringList SUFFIX_LIST{"_off", "_on"};
+ for (const QString &suffix : SUFFIX_LIST)
+ {
+ suffixedPaths.append(ao_app->get_image_suffix(ao_app->get_character_path(character, "emotions/button" + emotion_number + suffix)));
}
- QString image = suffixedPaths[static_cast<int>(on)];
- QString emoteComment = ao_app->get_emote_comment(p_char, p_emote);
- if (on && !file_exists(suffixedPaths[1])) {;
+ QString image = suffixedPaths[static_cast<int>(enabled)];
+ if (enabled && !file_exists(suffixedPaths[1]))
+ {
ui_selected->show();
image = suffixedPaths[0];
}
- else {
+ else
+ {
ui_selected->hide();
}
- set_image(image, emoteComment);
+ if (file_exists(image))
+ {
+ setText(QString());
+ setStyleSheet("QPushButton { border: none; }"
+ "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }");
+ setIcon(QPixmap(image).scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ setIconSize(size());
+ }
+ else
+ {
+ QString emote_comment = ao_app->get_emote_comment(character, emoteId);
+ setText(emote_comment);
+ setStyleSheet("QPushButton { border-image: url(); }"
+ "QToolTip { background-image: url(); color: #000000; "
+ "background-color: #ffffff; border: 0px; }");
+ setIcon(QIcon());
+ setIconSize(size());
+ }
}
-
-void AOEmoteButton::on_clicked() { emit emote_clicked(m_id); }
-