Truly independent web browser
UI/Qt: Make labels plain text unless they ask for another format
Andreas Kling196aba4dfdca
diff --git a/UI/Qt/PlainText.cpp b/UI/Qt/PlainText.cppindex cecac1d1f26..fd2e66c33bd 100644--- a/UI/Qt/PlainText.cpp+++ b/UI/Qt/PlainText.cpp@@ -16,6 +16,7 @@#include <QEvent>#include <QHelpEvent>#include <QKeyEvent>+#include <QLabel>#include <QMouseEvent>#include <QPainter>#include <QPointer>@@ -373,6 +374,14 @@ static Optional<ToolTipContent> tooltip_at(QWidget& widget, QPoint position)bool PlainTextEventFilter::eventFilter(QObject* object, QEvent* event){+ // NB: QLabel parses its text when it is first laid out or painted, and both polish the label first. This also+ // covers the labels inside a QMessageBox, and the label of QToolTip, were anything to still reach it.+ if (event->type() == QEvent::Polish) {+ if (auto* label = as_if<QLabel>(object); label && label->textFormat() == Qt::AutoText)+ label->setTextFormat(Qt::PlainText);+ return false;+ }+if (event->type() == QEvent::ToolTip) {auto* widget = as_if<QWidget>(object);if (!widget)diff --git a/UI/Qt/PlainText.h b/UI/Qt/PlainText.hindex 4bbbb00fb26..34c150fce74 100644--- a/UI/Qt/PlainText.h+++ b/UI/Qt/PlainText.h@@ -17,9 +17,13 @@ class QWidget;namespace Ladybird {-// Tooltips can hold text from web pages, and QToolTip treats any text that looks like rich text as rich text. So all-// tooltips are shown by this filter instead, as plain text in a window of ours: Widgets keep their tooltip text as it-// is, and no widget gets to see a QEvent::ToolTip. A tooltip that isn't found here is not shown.+// Tooltips and labels can hold text from web pages, and Qt treats any text that looks like rich text as rich text.+//+// So all tooltips are shown by this filter instead, as plain text in a window of ours: Widgets keep their tooltip text+// as it is, and no widget gets to see a QEvent::ToolTip. A tooltip that isn't found here is not shown.+//+// Labels become Qt::PlainText as they are polished, unless they explicitly ask for another format. A label that has its+// heightForWidth() called before it is polished has to set its format itself.class PlainTextEventFilter final : public QObject {Q_OBJECT