mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-01 11:29:20 +00:00
feat(Utils): add imagesHeight/imagesWidth options to encodeUrisToQmlFormat
This commit is contained in:
parent
737c52aa6c
commit
922ab78698
3 changed files with 20 additions and 5 deletions
|
|
@ -39,12 +39,15 @@ Item {
|
|||
padding: ChatStyle.entry.message.padding
|
||||
readOnly: true
|
||||
selectByMouse: true
|
||||
text: Utils.encodeUrisToQmlFormat($content)
|
||||
text: Utils.encodeUrisToQmlFormat($content, {
|
||||
imagesHeight: ChatStyle.entry.message.imagesHeight,
|
||||
imagesWidth: 'auto'
|
||||
})
|
||||
wrapMode: Text.Wrap
|
||||
|
||||
// See http://doc.qt.io/qt-5/qml-qtquick-text.html#textFormat-prop
|
||||
// and http://doc.qt.io/qt-5/richtext-html-subset.html
|
||||
textFormat: Text.RichText
|
||||
textFormat: Text.RichText // To supports links and imgs.
|
||||
|
||||
onLinkActivated: Qt.openUrlExternally(link)
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ QtObject {
|
|||
}
|
||||
|
||||
property QtObject message: QtObject {
|
||||
property int imagesHeight: 48
|
||||
property int padding: 8
|
||||
property int radius: 4
|
||||
|
||||
|
|
|
|||
|
|
@ -142,9 +142,13 @@ function qmlTypeof (object, className) {
|
|||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function encodeUrisToQmlFormat (text) {
|
||||
function encodeUrisToQmlFormat (text, options) {
|
||||
var images = ''
|
||||
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
|
||||
text = text
|
||||
.replace(/</g, '\u2063<')
|
||||
.replace(/>/g, '\u2063>')
|
||||
|
|
@ -156,8 +160,15 @@ function encodeUrisToQmlFormat (text) {
|
|||
|
||||
var ext = getExtension(match)
|
||||
if (includes([ 'jpg', 'jpeg', 'gif', 'png', 'svg' ], ext)) {
|
||||
images += '<a href="' + match +
|
||||
'"><img width="auto" height="48" src="' + match + '" /></a>'
|
||||
images += '<a href="' + match + '"><img' + (
|
||||
options.imageWidth != null
|
||||
? ' width="' + options.imagesWidth + '"'
|
||||
: ''
|
||||
) + (
|
||||
options.imageHeight != null
|
||||
? ' height="' + options.imagesHeight + '"'
|
||||
: ''
|
||||
) + 'src="' + match + '" /></a>'
|
||||
}
|
||||
|
||||
return '<a href="' + match + '">' + match + '</a>'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue