1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Make the popup layout more resistant to broken HTML content

This commit is contained in:
Martin Tůma 2024-01-17 08:57:08 +01:00
parent 866b2c27ca
commit c493f8cf16

View File

@ -7,6 +7,7 @@
#include <QBasicTimer> #include <QBasicTimer>
#include <QScreen> #include <QScreen>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QFormLayout>
#include <QApplication> #include <QApplication>
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
#include <QDesktopWidget> #include <QDesktopWidget>
@ -93,21 +94,29 @@ void PopupFrame::createLayout(const ToolTip &content)
} }
if (!content.list().isEmpty()) { if (!content.list().isEmpty()) {
QString html = "<table>"; QFormLayout *textLayout = new QFormLayout();
for (int i = 0; i < content.list().count(); i++) textLayout->setLabelAlignment(Qt::AlignRight);
html += "<tr><td align=\"right\"><b>" + content.list().at(i).key() textLayout->setHorizontalSpacing(5);
+ ":&nbsp;</b></td><td>" + content.list().at(i).value() textLayout->setVerticalSpacing(2);
+ "</td></tr>";
html += "</table>";
QLabel *label = new QLabel(html); for (int i = 0; i < content.list().count(); i++) {
label->setAlignment(Qt::AlignLeft); QLabel *key = new QLabel(content.list().at(i).key() + ":");
label->setIndent(1); key->setTextFormat(Qt::PlainText);
label->setTextInteractionFlags(Qt::TextBrowserInteraction); key->setAlignment(Qt::AlignTop);
label->setOpenExternalLinks(true); key->setStyleSheet("font-weight: bold");
label->setWordWrap(true); QLabel *value = new QLabel(content.list().at(i).value());
value->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::Preferred);
value->setTextFormat(Qt::RichText);
value->setAlignment(Qt::AlignTop);
value->setTextInteractionFlags(Qt::TextBrowserInteraction);
value->setOpenExternalLinks(true);
value->setWordWrap(true);
layout->addWidget(label); textLayout->addRow(key, value);
}
layout->addLayout(textLayout);
} }
setLayout(layout); setLayout(layout);