From d3f23708c43bc132c322b778b2aa8d31a68d1c0c Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 20 Sep 2019 15:54:45 +0300 Subject: [PATCH] Revert buttons using setIcon and use a better stylesheet method instead Fix evidence buttons and emote buttons being hardcoded size --- include/aoemotebutton.h | 2 +- include/aoevidencebutton.h | 2 +- src/aobutton.cpp | 10 ++++------ src/aocharbutton.cpp | 8 ++++++-- src/aoemotebutton.cpp | 12 ++++++------ src/aoevidencebutton.cpp | 21 ++++++++++----------- src/emotes.cpp | 2 +- src/evidence.cpp | 2 +- 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/include/aoemotebutton.h b/include/aoemotebutton.h index 4c31014..a13688b 100644 --- a/include/aoemotebutton.h +++ b/include/aoemotebutton.h @@ -11,7 +11,7 @@ class AOEmoteButton : public QPushButton Q_OBJECT public: - AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y); + AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y, int p_w, int p_h); void set_image(QString p_image, QString p_emote_comment); void set_char_image(QString p_char, int p_emote, QString suffix); diff --git a/include/aoevidencebutton.h b/include/aoevidencebutton.h index f7baa9f..53fa11f 100644 --- a/include/aoevidencebutton.h +++ b/include/aoevidencebutton.h @@ -13,7 +13,7 @@ class AOEvidenceButton : public QPushButton Q_OBJECT public: - AOEvidenceButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y); + AOEvidenceButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y, int p_w, int p_h); void set_image(QString p_image); void set_theme_image(QString p_image); diff --git a/src/aobutton.cpp b/src/aobutton.cpp index d80226f..9efe13d 100644 --- a/src/aobutton.cpp +++ b/src/aobutton.cpp @@ -20,17 +20,15 @@ void AOButton::set_image(QString p_image) if (file_exists(image_path)) { - this->setIcon(QIcon(image_path)); - this->setIconSize(this->size()); - this->setStyleSheet("border:0px"); this->setText(""); + this->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 if (file_exists(default_image_path)) { - this->setIcon(QIcon(default_image_path)); - this->setIconSize(this->size()); - this->setStyleSheet("border:0px"); this->setText(""); + this->setStyleSheet("QPushButton { border-image: url(\"" + default_image_path + "\"); }" + "QToolTip { background-image: url(); color: #000000; background-color: #ffffff; border: 0px; }"); } else return; diff --git a/src/aocharbutton.cpp b/src/aocharbutton.cpp index d571b95..6acad70 100644 --- a/src/aocharbutton.cpp +++ b/src/aocharbutton.cpp @@ -70,10 +70,14 @@ void AOCharButton::set_image(QString p_character) this->setText(""); if (file_exists(image_path)) - this->setStyleSheet("border-image:url(\"" + image_path + "\")"); + { + this->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 { - this->setStyleSheet("border-image:url()"); + this->setStyleSheet("QPushButton { border-image: url(); }" + "QToolTip { background-image: url(); color: #000000; background-color: #ffffff; border: 0px; }"); this->setText(p_character); } } diff --git a/src/aoemotebutton.cpp b/src/aoemotebutton.cpp index 8d68712..e42bb73 100644 --- a/src/aoemotebutton.cpp +++ b/src/aoemotebutton.cpp @@ -2,13 +2,13 @@ #include "file_functions.h" -AOEmoteButton::AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y) : QPushButton(p_parent) +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; this->move(p_x, p_y); - this->resize(40, 40); + this->resize(p_w, p_h); connect(this, SIGNAL(clicked()), this, SLOT(on_clicked())); } @@ -17,15 +17,15 @@ void AOEmoteButton::set_image(QString p_image, QString p_emote_comment) { if (file_exists(p_image)) { - this->setIcon(QIcon(p_image)); - this->setIconSize(this->size()); - this->setStyleSheet("border:0px"); this->setText(""); + this->setStyleSheet("QPushButton { border-image: url(\"" + p_image + "\") 0 0 0 0 stretch stretch; }" + "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }"); } else { this->setText(p_emote_comment); - this->setStyleSheet("border-image:url(\"\")"); + this->setStyleSheet("QPushButton { border-image: url(); }" + "QToolTip { background-image: url(); color: #000000; background-color: #ffffff; border: 0px; }"); } } diff --git a/src/aoevidencebutton.cpp b/src/aoevidencebutton.cpp index 871b477..61847f2 100644 --- a/src/aoevidencebutton.cpp +++ b/src/aoevidencebutton.cpp @@ -2,28 +2,27 @@ #include "file_functions.h" -AOEvidenceButton::AOEvidenceButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y) : QPushButton(p_parent) +AOEvidenceButton::AOEvidenceButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y, int p_w, int p_h) : QPushButton(p_parent) { ao_app = p_ao_app; m_parent = p_parent; - //HELLO AND WELCOME TO HARDCODE CENTRAL, MAY I TAKE YOUR FRESH ORDER OF PAIN AND SUFFERING ui_selected = new AOImage(this, ao_app); - ui_selected->resize(70, 70); + ui_selected->resize(p_w, p_h); // ui_selected->move(p_x, p_y); ui_selected->set_image("evidence_selected"); ui_selected->setAttribute(Qt::WA_TransparentForMouseEvents); ui_selected->hide(); ui_selector = new AOImage(this, ao_app); - ui_selector->resize(70, 70); + ui_selector->resize(p_w, p_h); // ui_selector->move(p_x - 1, p_y - 1); ui_selector->set_image("evidence_selector"); ui_selector->setAttribute(Qt::WA_TransparentForMouseEvents); ui_selector->hide(); this->move(p_x, p_y); - this->resize(70, 70); + this->resize(p_w, p_h); // this->setAcceptDrops(true); connect(this, SIGNAL(clicked()), this, SLOT(on_clicked())); @@ -32,24 +31,24 @@ AOEvidenceButton::AOEvidenceButton(QWidget *p_parent, AOApplication *p_ao_app, i void AOEvidenceButton::set_image(QString p_image) { QString image_path = ao_app->get_evidence_path(p_image); - qDebug() << image_path << p_image; if (file_exists(p_image)) { this->setText(""); - this->setIcon(QIcon(p_image)); + this->setStyleSheet("QPushButton { border-image: url(\"" + p_image + "\") 0 0 0 0 stretch stretch; }" + "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }"); } else if (file_exists(image_path)) { this->setText(""); - this->setIcon(QIcon(image_path)); + this->setStyleSheet("QPushButton { border-image: url(\"" + image_path + "\") 0 0 0 0 stretch stretch; }" + "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }"); } else { this->setText(p_image); - this->setIcon(QIcon()); + this->setStyleSheet("QPushButton { border-image: url(); }" + "QToolTip { background-image: url(); color: #000000; background-color: #ffffff; border: 0px; }"); } - this->setIconSize(this->size()); - this->setStyleSheet("border:0px"); } void AOEvidenceButton::set_theme_image(QString p_image) diff --git a/src/emotes.cpp b/src/emotes.cpp index a08043c..3e96824 100644 --- a/src/emotes.cpp +++ b/src/emotes.cpp @@ -52,7 +52,7 @@ void Courtroom::refresh_emotes() int x_pos = (button_width + x_spacing) * x_mod_count; int y_pos = (button_height + y_spacing) * y_mod_count; - AOEmoteButton *f_emote = new AOEmoteButton(ui_emotes, ao_app, x_pos, y_pos); + AOEmoteButton *f_emote = new AOEmoteButton(ui_emotes, ao_app, x_pos, y_pos, button_width, button_height); ui_emote_list.append(f_emote); diff --git a/src/evidence.cpp b/src/evidence.cpp index 727f4bf..b04a9d6 100644 --- a/src/evidence.cpp +++ b/src/evidence.cpp @@ -74,7 +74,7 @@ void Courtroom::refresh_evidence() int x_pos = (button_width + x_spacing) * x_mod_count; int y_pos = (button_height + y_spacing) * y_mod_count; - AOEvidenceButton *f_evidence = new AOEvidenceButton(ui_evidence_buttons, ao_app, x_pos, y_pos); + AOEvidenceButton *f_evidence = new AOEvidenceButton(ui_evidence_buttons, ao_app, x_pos, y_pos, button_width, button_height); ui_evidence_list.append(f_evidence);