fix(@desktop/chat): abnormal CPU usage and slowness

Fixes: #3626
This commit is contained in:
Sale Djenic 2021-09-24 11:55:48 +02:00 committed by Iuri Matias
parent 32ca947850
commit faaaa24f39
1 changed files with 39 additions and 68 deletions

View File

@ -8,45 +8,31 @@ Rectangle {
id: root id: root
property bool noHover: false property bool noHover: false
property bool noMouseArea: false property bool noMouseArea: false
property bool showLoadingIndicator: true
property alias source: image.source property alias source: image.source
property alias fillMode: image.fillMode property alias fillMode: image.fillMode
property bool showLoadingIndicator: true
signal loaded signal loaded
signal clicked signal clicked
color: Style.current.backgroundHover color: Style.current.backgroundHover
state: showLoadingIndicator ? "loading" : "ready"
radius: width / 2 radius: width / 2
states: [ states: [
State { State {
name: "loading" name: "loading"
when: image.status === Image.Loading when: image.status === Image.Loading
PropertyChanges { PropertyChanges {
target: loading target: loader
active: true sourceComponent: loadingIndicator
}
PropertyChanges {
target: reload
visible: false
}
PropertyChanges {
target: image
visible: false
} }
}, },
State { State {
name: "error" name: "error"
when: image.status === Image.Error when: image.status === Image.Error
PropertyChanges { PropertyChanges {
target: loading target: loader
active: false sourceComponent: reload
}
PropertyChanges {
target: reload
visible: true
}
PropertyChanges {
target: image
visible: false
} }
}, },
State { State {
@ -57,18 +43,8 @@ Rectangle {
color: Style.current.transparent color: Style.current.transparent
} }
PropertyChanges { PropertyChanges {
target: loading target: loader
active: false sourceComponent: undefined
}
PropertyChanges {
target: reload
visible: false
}
PropertyChanges {
target: image
visible: true
height: root.height
width: root.width
} }
} }
] ]
@ -107,49 +83,44 @@ Rectangle {
} }
} }
Loader { Component {
id: loading
sourceComponent: loadingIndicator
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
active: false
}
SVGImage {
id: reload id: reload
source: "../app/img/reload.svg" SVGImage {
width: 15.5 source: "../app/img/reload.svg"
height: 19.5 mipmap: false
fillMode: Image.PreserveAspectFit width: 15.5
anchors.verticalCenter: parent.verticalCenter height: 19.5
anchors.horizontalCenter: parent.horizontalCenter fillMode: Image.PreserveAspectFit
ColorOverlay { ColorOverlay {
anchors.fill: parent anchors.fill: parent
source: parent source: parent
color: Style.current.textColor color: Style.current.textColor
antialiasing: true antialiasing: true
} }
MouseArea { MouseArea {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
root.reload() root.reload()
}
} }
} }
} }
Loader {
id: loader
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
}
Image { Image {
id: image id: image
width: 0 anchors.fill: parent
height: 0
sourceSize.width: root.width * 2
sourceSize.height: root.height * 2
source: root.source
horizontalAlignment: Image.AlignHCenter horizontalAlignment: Image.AlignHCenter
verticalAlignment: Image.AlignVCenter verticalAlignment: Image.AlignVCenter
cache: true cache: true
onStatusChanged: { onStatusChanged: {
if (image.status === Image.Ready) { if (status === Image.Ready) {
loaded() loaded()
} }
} }