Commit 922ab786 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Utils): add `imagesHeight`/`imagesWidth` options to `encodeUrisToQmlFormat`

parent 737c52aa
......@@ -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&lt;')
.replace(/>/g, '\u2063&gt;')
......@@ -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>'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment