Use ES6 template strings

This commit is contained in:
miruka 2019-11-18 03:57:13 -04:00
parent 2123f5a66f
commit 5a70adcc93
10 changed files with 18 additions and 27 deletions

View File

@ -30,8 +30,6 @@
- Is auto-sizing actually needed, or can we just set a default manual size? - Is auto-sizing actually needed, or can we just set a default manual size?
- Reducable room sidepane, swipe to show full-window - Reducable room sidepane, swipe to show full-window
- When qml syntax highlighting supports ES6 string interpolation, use that
- Fixes - Fixes
- CPU usage - CPU usage
- `code` not colored in room subtitle - `code` not colored in room subtitle

View File

@ -8,12 +8,7 @@ Image {
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
visible: Boolean(svgName) visible: Boolean(svgName)
source: source: svgName ? `../../icons/${iconPack}/${svgName}.svg` : ""
svgName ?
("../../icons/" + (theme ? theme.icons.preferredPack : "thin") +
"/" + svgName + ".svg") :
""
sourceSize.width: svgName ? dimension : 0 sourceSize.width: svgName ? dimension : 0
sourceSize.height: svgName ? dimension : 0 sourceSize.height: svgName ? dimension : 0
@ -21,6 +16,7 @@ Image {
property string svgName: "" property string svgName: ""
property int dimension: 20 property int dimension: 20
property color colorize: theme.icons.colorize property color colorize: theme.icons.colorize
property string iconPack: theme ? theme.icons.preferredPack : "thin"
layer.enabled: ! Qt.colorEqual(colorize, "transparent") layer.enabled: ! Qt.colorEqual(colorize, "transparent")

View File

@ -68,13 +68,13 @@ Rectangle {
} }
HToolTip { HToolTip {
text: name && topic ? (name + "<br>" + topic) : (name || topic) text: name && topic ? (`${name}<br>${topic}`) : (name || topic)
label.textFormat: Text.StyledText label.textFormat: Text.StyledText
visible: text && (nameHover.hovered || topicHover.hovered) visible: text && (nameHover.hovered || topicHover.hovered)
readonly property string name: readonly property string name:
roomName.truncated ? roomName.truncated ?
("<b>" + chatPage.roomInfo.display_name + "</b>") : "" (`<b>${chatPage.roomInfo.display_name}</b>`) : ""
readonly property string topic: readonly property string topic:
roomTopic.truncated ? chatPage.roomInfo.topic : "" roomTopic.truncated ? chatPage.roomInfo.topic : ""
} }

View File

@ -19,7 +19,7 @@ HRowLayout {
readonly property string timeText: Utils.formatTime(model.date, false) readonly property string timeText: Utils.formatTime(model.date, false)
readonly property string localEchoText: readonly property string localEchoText:
model.is_local_echo ? model.is_local_echo ?
"&nbsp;<font size=" + theme.fontSize.small + "px>⏳</font>" : `&nbsp;<font size=${theme.fontSize.small}px></font>` :
"" ""
readonly property bool pureMedia: ! contentText && linksRepeater.count readonly property bool pureMedia: ! contentText && linksRepeater.count
@ -97,15 +97,14 @@ HRowLayout {
// For some reason, if there's only one space, // For some reason, if there's only one space,
// times will be on their own lines most of the time. // times will be on their own lines most of the time.
" " + " " +
"<font size=" + theme.fontSize.small + `<font size=${theme.fontSize.small}px ` +
"px color=" + theme.chat.message.date + '>' + `color=${theme.chat.message.date}>` +
timeText + timeText +
"</font>" + "</font>" +
// Local echo icon // Local echo icon
(model.is_local_echo ? (model.is_local_echo ?
"&nbsp;<font size=" + theme.fontSize.small + `&nbsp;<font size=${theme.fontSize.small}px></font>` : "")
"px>⏳</font>" : "")
transform: Translate { x: xOffset } transform: Translate { x: xOffset }

View File

@ -15,7 +15,7 @@ HFileDialogOpener {
if (destroyWhenDone) destroy() if (destroyWhenDone) destroy()
}, },
(type, args, error, traceback) => { (type, args, error, traceback) => {
console.error("python:\n" + traceback) console.error(`python:\n${traceback}`)
if (destroyWhenDone) destroy() if (destroyWhenDone) destroy()
}) })
} }

View File

@ -6,7 +6,7 @@ HCheckBox {
subtitle.text: subtitle.text:
qsTr("Protect the room against eavesdropper. Only you " + qsTr("Protect the room against eavesdropper. Only you " +
"and those you trust can read the conversation.") + "and those you trust can read the conversation.") +
"<br><font color='" + theme.colors.middleBackground + "'>" + `<br><font color="${theme.colors.middleBackground}">` +
qsTr("Cannot be disabled later!") + qsTr("Cannot be disabled later!") +
"</font>" "</font>"
subtitle.textFormat: Text.StyledText subtitle.textFormat: Text.StyledText

View File

@ -83,9 +83,7 @@ HTileDelegate {
return text.replace( return text.replace(
/< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g, /< *span +class=['"]?quote['"]? *>(.+?)<\/ *span *>/g,
'<font color="' + `<font color="${theme.sidePane.room.subtitleQuote}">$1</font>`,
theme.sidePane.room.subtitleQuote +
'">$1</font>',
) )
} }

View File

@ -116,7 +116,7 @@ Item {
} }
function showPage(name, properties={}) { function showPage(name, properties={}) {
let path = "Pages/" + name + ".qml" let path = `Pages/${name}.qml`
_show(path, properties) _show(path, properties)
window.uiState.page = path window.uiState.page = path

View File

@ -23,7 +23,7 @@ function onCoroutineDone(uuid, result, error, traceback) {
onError ? onError ?
onError(type, args, error, traceback) : onError(type, args, error, traceback) :
console.error("python: " + uuid + "\n" + traceback) console.error(`python: ${uuid}\n${traceback}`)
} else if (onSuccess) { onSuccess(result) } } else if (onSuccess) { onSuccess(result) }

View File

@ -85,7 +85,7 @@ function nameColor(name) {
function coloredNameHtml(name, userId, displayText=null, disambiguate=false) { function coloredNameHtml(name, userId, displayText=null, disambiguate=false) {
// substring: remove leading @ // substring: remove leading @
return "<font color='" + nameColor(name || userId.substring(1)) + "'>" + return `<font color="${nameColor(name || userId.substring(1))}">` +
escapeHtml(displayText || name || userId) + escapeHtml(displayText || name || userId) +
"</font>" "</font>"
} }
@ -210,11 +210,11 @@ function formatDuration(milliseconds) {
let minutes = Math.floor((totalSeconds % 3600) / 60) let minutes = Math.floor((totalSeconds % 3600) / 60)
let seconds = Math.floor(totalSeconds % 60) let seconds = Math.floor(totalSeconds % 60)
if (seconds < 10) seconds = "0" + seconds if (seconds < 10) seconds = `0${seconds}`
if (hours < 1) return minutes + ":" + seconds if (hours < 1) return `${minutes}:${seconds}`
if (minutes < 10) minutes = "0" + minutes if (minutes < 10) minutes = `0${minutes}`
return hours + ":" + minutes + ":" + seconds return `${hours}:${minutes}:${seconds}`
} }