moment/src/gui/PageLoader.qml

97 lines
2.4 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Window 2.12
import QtGraphicalEffects 1.12
import "Base"
import "MainPane"
HLoader {
id: pageLoader
// List of previously loaded [componentUrl, {properties}]
property var history: []
property int historyLength: 20
signal recycled()
signal previousShown(string componentUrl, var properties)
function show(componentUrl, properties={}) {
history.unshift([componentUrl, properties])
if (history.length > historyLength) history.pop()
const recycle =
window.uiState.page === componentUrl &&
componentUrl === "Pages/Chat/Chat.qml" &&
item
if (recycle) {
for (const [prop, value] of Object.entries(properties))
item[prop] = value
recycled()
} else {
pageLoader.setSource(componentUrl, properties)
window.uiState.page = componentUrl
}
window.uiState.pageProperties = properties
window.uiStateChanged()
}
function showRoom(userId, roomId) {
show("Pages/Chat/Chat.qml", {userId, roomId})
}
function showPrevious(timesBack=1) {
timesBack = Math.min(timesBack, history.length - 1)
if (timesBack < 1) return false
2020-03-08 19:46:20 +11:00
const [componentUrl, properties] = history[timesBack]
show(componentUrl, properties)
previousShown(componentUrl, properties)
return true
}
function closeMainPane() {
if (mainPane.collapse) mainPane.close()
}
function takeFocus() {
pageLoader.item.forceActiveFocus()
closeMainPane()
}
clip: appearAnimation.running
2020-09-04 00:49:15 +10:00
onLoaded: { takeFocus(); appearAnimation.restart() }
onRecycled: { closeMainPane(); appearAnimation.restart() }
Component.onCompleted: {
if (! py.startupAnyAccountsSaved) {
pageLoader.show("AddAccount/AddAccount", {"header.show": false})
return
}
pageLoader.show(window.uiState.page, window.uiState.pageProperties)
}
HNumberAnimation {
id: appearAnimation
target: pageLoader.item
property: "x"
2020-09-04 00:49:15 +10:00
from: -pageLoader.width
to: 0
2020-09-04 00:49:15 +10:00
easing.type: Easing.OutCirc
factor: 2
}
HShortcut {
sequences: window.settings.keys.goToLastPage
onActivated: showPrevious()
}
}