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

This commit is contained in:
Ronan Abhamon 2016-11-09 15:16:42 +01:00
parent 737c52aa6c
commit 922ab78698
3 changed files with 20 additions and 5 deletions

View file

@ -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)

View file

@ -47,6 +47,7 @@ QtObject {
}
property QtObject message: QtObject {
property int imagesHeight: 48
property int padding: 8
property int radius: 4

View file

@ -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>'