From 4b507fa238a30ea8b874dd69f300a9dec3aaf486 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Wed, 19 Nov 2025 05:10:26 +0800 Subject: [PATCH 1/2] feat: Tooltip supports rich text parsing --- Modules/Tooltip/Tooltip.qml | 3 ++- Widgets/NText.qml | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Modules/Tooltip/Tooltip.qml b/Modules/Tooltip/Tooltip.qml index b982ff1fc..85999b860 100644 --- a/Modules/Tooltip/Tooltip.qml +++ b/Modules/Tooltip/Tooltip.qml @@ -414,7 +414,8 @@ PopupWindow { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter wrapMode: Text.WordWrap - width: root.maxWidth - (root.padding * 2) + width: Math.min(implicitWidth, root.maxWidth - (root.padding * 2)) + richTextEnabled: true } } } diff --git a/Widgets/NText.qml b/Widgets/NText.qml index 3dd3933fa..687900156 100644 --- a/Widgets/NText.qml +++ b/Widgets/NText.qml @@ -17,6 +17,8 @@ Text { return fontScale; } + property bool richTextEnabled: false + font.family: root.family font.weight: Style.fontWeightMedium font.pointSize: root.pointSize * fontScale @@ -24,4 +26,6 @@ Text { elide: Text.ElideRight wrapMode: Text.NoWrap verticalAlignment: Text.AlignVCenter + + textFormat: richTextEnabled ? Text.RichText : Text.PlainText } From 1a4f151bbcd2f56de50cde9f784c37e06b30deff Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Wed, 19 Nov 2025 05:11:27 +0800 Subject: [PATCH 2/2] Enhanced rich text parsing for specific plain text content --- Modules/Bar/Widgets/CustomButton.qml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Modules/Bar/Widgets/CustomButton.qml b/Modules/Bar/Widgets/CustomButton.qml index 9cc000bac..c8b8c5e5a 100644 --- a/Modules/Bar/Widgets/CustomButton.qml +++ b/Modules/Bar/Widgets/CustomButton.qml @@ -158,7 +158,7 @@ Item { const parsed = JSON.parse(lineToParse); const text = parsed.text || ""; const icon = parsed.icon || ""; - const tooltip = parsed.tooltip || ""; + let tooltip = parsed.tooltip || ""; if (checkCollapse(text)) { _dynamicText = ""; @@ -169,7 +169,8 @@ Item { _dynamicText = text; _dynamicIcon = icon; - _dynamicTooltip = tooltip; + + _dynamicTooltip = toHtml(tooltip); return; } catch (e) { Logger.w("CustomButton", `Failed to parse JSON. Content: "${lineToParse}"`); @@ -185,7 +186,7 @@ Item { _dynamicText = contentStr; _dynamicIcon = ""; - _dynamicTooltip = ""; + _dynamicTooltip = toHtml(contentStr); } function checkCollapse(text) { @@ -244,6 +245,25 @@ Item { } } + function toHtml(str) { + const htmlRegex = /<\/?[a-zA-Z][\s\S]*>/; + + if (htmlRegex.test(str)) { + return str; + } + + const escaped = str + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); + + const withBreaks = escaped.replace(/\r\n|\r|\n/g, "
"); + + return withBreaks; + } + function runTextCommand() { if (!textCommand || textCommand.length === 0) return;