Warning, /multimedia/elisa/src/qml/ImageWithFallback.qml is written in an unsupported language. File is not indexed.

0001 /*
0002    SPDX-FileCopyrightText: 2020 (c) Alexander Stippich <a.stippich@gmx.net>
0003 
0004    SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 import QtQuick 2.7
0008 
0009 Item {
0010     id: imageWithFallback
0011     property url source
0012     property url fallback
0013     property bool usingFallback: false
0014     property alias sourceSize: image.sourceSize
0015     readonly property alias status: image.status
0016     property alias fillMode: image.fillMode
0017     property alias asynchronous: image.asynchronous
0018     property alias mipmap: image.mipmap
0019     property alias paintedWidth: image.paintedWidth
0020     property alias paintedHeight: image.paintedHeight
0021 
0022     implicitWidth: image.width
0023     implicitHeight: image.height
0024 
0025     onSourceChanged: {
0026         image.source = getImageUrl()
0027     }
0028 
0029     function getImageUrl() {
0030         if (source == '' || source === undefined) {
0031             usingFallback = true;
0032             return fallback;
0033         } else {
0034             usingFallback = false;
0035             return source;
0036         }
0037     }
0038 
0039     Image {
0040         id: image
0041         anchors.fill: parent
0042         cache: false
0043         source: imageWithFallback.getImageUrl()
0044 
0045         onStatusChanged: {
0046             if (status === Image.Error) {
0047                 imageWithFallback.usingFallback = true;
0048                 image.source = imageWithFallback.fallback;
0049             }
0050         }
0051     }
0052 }