Skip to content

Commit 6c27d83

Browse files
authored
Merge pull request #1901 from zedwick/armored-chat_imagefix
Chat app: Fix images not loading
2 parents b2d0d1a + 5dd8662 commit 6c27d83

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

scripts/communityScripts/armored-chat/qml/ChatMessage.qml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Item {
3535
}
3636

3737
// Message body
38-
TextEdit {
38+
TextEdit {
39+
id: messageText;
3940
text: delegateMessage;
4041
color: "white";
4142
font.pixelSize: 18;
@@ -56,6 +57,30 @@ Item {
5657
Qt.openUrlExternally(link);
5758
}
5859
}
60+
61+
Component.onCompleted: {
62+
// Images do not appear when done loading until
63+
// the component is redrawn, which it does not do
64+
// automatically; so we need to create a hidden
65+
// Image object and wait for that to load
66+
// before we cause it to redraw by altering the content.
67+
var re = /<img[^>]+src="([^"]+)"[^>]+>/gi
68+
var m;
69+
while ((m = re.exec(text)) !== null) {
70+
var loader = Qt.createQmlObject('import QtQuick 2.0; Image {}', messageText);
71+
loader.source = m[1];
72+
loader.visible = false;
73+
loader.onStatusChanged.connect(function () {
74+
if (loader.status === Image.Ready) {
75+
// Alter the content of messageText
76+
// to prompt it to redraw
77+
var originalText = messageText.text;
78+
messageText.text = ""; // force a change
79+
messageText.text = originalText;
80+
}
81+
});
82+
}
83+
}
5984
}
6085
}
6186

@@ -73,4 +98,4 @@ Item {
7398
width: 5;
7499
height: parent.height;
75100
}
76-
}
101+
}

0 commit comments

Comments
 (0)