Fixed links tooltip

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-06-25 11:36:37 +03:00
parent ce4a86fbcd
commit 40fbae8ff6
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
2 changed files with 24 additions and 14 deletions

View File

@ -34,13 +34,24 @@
* limitations under the License. * limitations under the License.
*/ */
#include <QLabel>
#include <QMessageBox> #include <QMessageBox>
#include <QToolTip>
#include "InfoFrame.h" #include "InfoFrame.h"
#include "ui_InfoFrame.h" #include "ui_InfoFrame.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
void setupLinkTooTip(QLabel* label)
{
QObject::connect(label, &QLabel::linkHovered, [label](const QString& link) {
if (!link.isEmpty() && !link.startsWith("http"))
return;
label->setToolTip(link);
});
}
InfoFrame::InfoFrame(QWidget* parent) : QFrame(parent), ui(new Ui::InfoFrame) InfoFrame::InfoFrame(QWidget* parent) : QFrame(parent), ui(new Ui::InfoFrame)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -48,6 +59,12 @@ InfoFrame::InfoFrame(QWidget* parent) : QFrame(parent), ui(new Ui::InfoFrame)
ui->nameLabel->setHidden(true); ui->nameLabel->setHidden(true);
ui->licenseLabel->setHidden(true); ui->licenseLabel->setHidden(true);
ui->issueTrackerLabel->setHidden(true); ui->issueTrackerLabel->setHidden(true);
setupLinkTooTip(ui->iconLabel);
setupLinkTooTip(ui->descriptionLabel);
setupLinkTooTip(ui->nameLabel);
setupLinkTooTip(ui->licenseLabel);
setupLinkTooTip(ui->issueTrackerLabel);
updateHiddenState(); updateHiddenState();
} }
@ -66,7 +83,6 @@ void InfoFrame::updateWithMod(Mod const& m)
QString text = ""; QString text = "";
QString name = ""; QString name = "";
QString link = m.metaurl(); QString link = m.metaurl();
QString toolTip = "";
if (m.name().isEmpty()) if (m.name().isEmpty())
name = m.internal_id(); name = m.internal_id();
else else
@ -76,12 +92,11 @@ void InfoFrame::updateWithMod(Mod const& m)
text = name; text = name;
else { else {
text = "<a href=\"" + link + "\">" + name + "</a>"; text = "<a href=\"" + link + "\">" + name + "</a>";
toolTip = link;
} }
if (!m.authors().isEmpty()) if (!m.authors().isEmpty())
text += " by " + m.authors().join(", "); text += " by " + m.authors().join(", ");
setName(text, toolTip); setName(text);
if (m.description().isEmpty()) { if (m.description().isEmpty()) {
setDescription(QString()); setDescription(QString());
@ -89,14 +104,14 @@ void InfoFrame::updateWithMod(Mod const& m)
setDescription(m.description()); setDescription(m.description());
} }
setImage(m.icon({64,64})); setImage(m.icon({ 64, 64 }));
auto licenses = m.licenses(); auto licenses = m.licenses();
QString licenseText = ""; QString licenseText = "";
if (!licenses.empty()) { if (!licenses.empty()) {
for (auto l : licenses) { for (auto l : licenses) {
if (!licenseText.isEmpty()) { if (!licenseText.isEmpty()) {
licenseText += "\n"; // add newline between licenses licenseText += "\n"; // add newline between licenses
} }
if (!l.name.isEmpty()) { if (!l.name.isEmpty()) {
if (l.url.isEmpty()) { if (l.url.isEmpty()) {
@ -226,29 +241,24 @@ void InfoFrame::updateHiddenState()
} }
} }
void InfoFrame::setName(QString text, QString toolTip) void InfoFrame::setName(QString text)
{ {
if (text.isEmpty()) { if (text.isEmpty()) {
ui->nameLabel->setHidden(true); ui->nameLabel->setHidden(true);
ui->nameLabel->setToolTip({});
} else { } else {
ui->nameLabel->setText(text); ui->nameLabel->setText(text);
ui->nameLabel->setHidden(false); ui->nameLabel->setHidden(false);
ui->nameLabel->setToolTip(toolTip);
} }
updateHiddenState(); updateHiddenState();
} }
void InfoFrame::setDescription(QString text) void InfoFrame::setDescription(QString text)
{ {
if(text.isEmpty()) if (text.isEmpty()) {
{
ui->descriptionLabel->setHidden(true); ui->descriptionLabel->setHidden(true);
updateHiddenState(); updateHiddenState();
return; return;
} } else {
else
{
ui->descriptionLabel->setHidden(false); ui->descriptionLabel->setHidden(false);
updateHiddenState(); updateHiddenState();
} }

View File

@ -52,7 +52,7 @@ class InfoFrame : public QFrame {
InfoFrame(QWidget* parent = nullptr); InfoFrame(QWidget* parent = nullptr);
~InfoFrame() override; ~InfoFrame() override;
void setName(QString text = {}, QString toolTip = {}); void setName(QString text = {});
void setDescription(QString text = {}); void setDescription(QString text = {});
void setImage(QPixmap img = {}); void setImage(QPixmap img = {});
void setLicense(QString text = {}); void setLicense(QString text = {});