C

Qt Quick Ultralite image_cache Example

/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
import QtQuick 2.15 Rectangle { color: "black" property int reloadInSeconds: 15 property int reloadInMs: 1000 * reloadInSeconds property int showCountDownSeconds: 3 property int showCountDownMs: 1000 * showCountDownSeconds property int remainingSeconds: 0 property int showDescriptionMs: 1000 * 5 ListView { anchors.fill: parent orientation: Qt.Horizontal model: ImageModel { id: myImageModel } spacing: 4 delegate: Image { anchors.fill: parent fillMode: Image.Pad source: model.imagePath } } Rectangle { id: infoBox color: "white" width: parent.width height: infoBoxText.height + 4 anchors.verticalCenter: parent.verticalCenter visible: false Text { id: infoBoxText anchors.centerIn: parent } } Timer { id: reloadImagesTimer interval: reloadInMs - showCountDownMs // Start the timer when the application starts. running: true onTriggered: { // We unfortunately do not have Timer::triggeredOnStart // in qul at the moment, therefore we init the values here. remainingSeconds = showCountDownSeconds infoBoxText.text = "Will reload in " + remainingSeconds + "..." infoBox.visible = true countDownTextVisible.start() } } Timer { id: countDownTextVisible interval: 1000 // Repeat every second, so we can update the countdown text. repeat: true onTriggered: { remainingSeconds -= 1 infoBoxText.text = "Will reload in " + remainingSeconds + "..." if (remainingSeconds == 0) { infoBox.visible = false; myImageModel.swapImages(); countDownTextVisible.stop() reloadImagesTimer.start() } } } Timer { id: infoBoxHideTimer onTriggered: infoBox.visible = false } Component.onCompleted: { infoBoxText.text = "Swipe to view photos.\nContent reloads every " + reloadInSeconds + " seconds." infoBoxHideTimer.interval = showDescriptionMs infoBox.visible = true infoBoxHideTimer.start() } }