diff --git a/src/declarativeimports/plasmastyle/ButtonStyle.qml b/src/declarativeimports/plasmastyle/ButtonStyle.qml --- a/src/declarativeimports/plasmastyle/ButtonStyle.qml +++ b/src/declarativeimports/plasmastyle/ButtonStyle.qml @@ -28,6 +28,7 @@ import org.kde.plasma.components 2.0 as PlasmaComponents import "private" as Private +import "private/Util.js" as Util QtQuickControlStyle.ButtonStyle { id: style @@ -72,7 +73,8 @@ PlasmaComponents.Label { id: label anchors.verticalCenter: parent.verticalCenter - text: QtQuickControlsPrivate.StyleHelpers.stylizeMnemonics(control.text) + text: Util.stylizeEscapedMnemonics(Util.toHtmlEscaped(control.text)) + textFormat: Text.StyledText font: control.font || theme.defaultFont visible: control.text != "" Layout.fillWidth: true diff --git a/src/declarativeimports/plasmastyle/ToolButtonStyle.qml b/src/declarativeimports/plasmastyle/ToolButtonStyle.qml --- a/src/declarativeimports/plasmastyle/ToolButtonStyle.qml +++ b/src/declarativeimports/plasmastyle/ToolButtonStyle.qml @@ -28,6 +28,7 @@ import org.kde.plasma.components 2.0 as PlasmaComponents import "private" as Private +import "private/Util.js" as Util QtQuickControlStyle.ButtonStyle { id: style @@ -95,7 +96,8 @@ id: label anchors.verticalCenter: parent.verticalCenter Layout.minimumWidth: implicitWidth - text: QtQuickControlsPrivate.StyleHelpers.stylizeMnemonics(control.text) + text: Util.stylizeEscapedMnemonics(Util.toHtmlEscaped(control.text)) + textFormat: Text.StyledText font: control.font || theme.defaultFont visible: control.text != "" Layout.fillWidth: true diff --git a/src/declarativeimports/plasmastyle/private/Util.js b/src/declarativeimports/plasmastyle/private/Util.js new file mode 100644 --- /dev/null +++ b/src/declarativeimports/plasmastyle/private/Util.js @@ -0,0 +1,49 @@ +/* + * Copyright 2017 by Fabian Vogt + * Copyright 2017 by Kai Uwe Broulik + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. + */ + +.pragma library + +/* Like QString::toHtmlEscaped */ +function toHtmlEscaped(s) { + return s.replace(/[&<>]/g, function (tag) { + return { + '&': '&', + '<': '<', + '>': '>' + }[tag] || tag + }); +} + +function underlineAmpersands(match, p) { + if(p == "&") + return p; + + return "" + p + ""; +} + +/* This function is a replacement for the flawed + * QtQuickControlsPrivate.StyleHelpers.stylizeMnemonics. + * It scans the passed text for mnemonics, to put them into HTML + * tags. This means it emits HTML, but accepts only plaintext. + * Simply passing HTML escaped plaintext won't work, as it would then + * replace < with lt; so we need to implement it ourselves. */ +function stylizeEscapedMnemonics(text) { + return text.replace(/&(&|.)/g, underlineAmpersands); +}