2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-19 08:00:02 +11:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2020-03-17 00:04:59 +11:00
|
|
|
import QtQuick.Window 2.12
|
2019-12-19 08:00:02 +11:00
|
|
|
import QtGraphicalEffects 1.12
|
|
|
|
import "Base"
|
|
|
|
import "MainPane"
|
|
|
|
|
|
|
|
HLoader {
|
|
|
|
id: pageLoader
|
2020-05-14 12:47:04 +10:00
|
|
|
|
2019-12-19 08:00:02 +11:00
|
|
|
property bool isWide: width > theme.contentIsWideAbove
|
|
|
|
|
|
|
|
// List of previously loaded [componentUrl, {properties}]
|
|
|
|
property var history: []
|
|
|
|
property int historyLength: 20
|
|
|
|
|
2020-03-12 03:53:55 +11:00
|
|
|
readonly property alias appearAnimation: appearAnimation
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
signal previousShown(string componentUrl, var properties)
|
2019-12-19 08:00:02 +11:00
|
|
|
|
|
|
|
function _show(componentUrl, properties={}) {
|
|
|
|
history.unshift([componentUrl, properties])
|
|
|
|
if (history.length > historyLength) history.pop()
|
|
|
|
|
|
|
|
pageLoader.setSource(componentUrl, properties)
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPage(name, properties={}) {
|
2020-03-08 19:46:20 +11:00
|
|
|
const path = `Pages/${name}.qml`
|
2019-12-19 08:00:02 +11:00
|
|
|
_show(path, properties)
|
|
|
|
|
|
|
|
window.uiState.page = path
|
|
|
|
window.uiState.pageProperties = properties
|
|
|
|
window.uiStateChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
function showRoom(userId, roomId) {
|
2020-09-03 04:42:40 +10:00
|
|
|
if (window.uiState.page === "Pages/Chat/Chat.qml" && item) {
|
|
|
|
// XXX: showPrevious
|
|
|
|
item.userId = userId
|
|
|
|
item.roomId = roomId
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-19 08:00:02 +11:00
|
|
|
_show("Pages/Chat/Chat.qml", {userId, roomId})
|
|
|
|
|
|
|
|
window.uiState.page = "Pages/Chat/Chat.qml"
|
|
|
|
window.uiState.pageProperties = {userId, roomId}
|
|
|
|
window.uiStateChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
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]
|
2019-12-19 08:00:02 +11:00
|
|
|
|
|
|
|
_show(componentUrl, properties)
|
|
|
|
|
|
|
|
window.uiState.page = componentUrl
|
|
|
|
window.uiState.pageProperties = properties
|
|
|
|
window.uiStateChanged()
|
2020-05-14 12:47:04 +10:00
|
|
|
previousShown(componentUrl, properties)
|
2019-12-19 08:00:02 +11:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
function takeFocus() {
|
|
|
|
pageLoader.item.forceActiveFocus()
|
|
|
|
if (mainPane.collapse) mainPane.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
clip: appearAnimation.running
|
|
|
|
|
|
|
|
onLoaded: { takeFocus(); appearAnimation.start() }
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
if (! py.startupAnyAccountsSaved) {
|
|
|
|
pageLoader.showPage(
|
|
|
|
"AddAccount/AddAccount", {"header.show": false},
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const page = window.uiState.page
|
|
|
|
const props = window.uiState.pageProperties
|
|
|
|
|
|
|
|
if (page === "Pages/Chat/Chat.qml") {
|
|
|
|
pageLoader.showRoom(props.userId, props.roomId)
|
|
|
|
} else {
|
|
|
|
pageLoader._show(page, props)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 08:00:02 +11:00
|
|
|
HNumberAnimation {
|
|
|
|
id: appearAnimation
|
|
|
|
target: pageLoader.item
|
|
|
|
property: "x"
|
|
|
|
from: -300
|
|
|
|
to: 0
|
|
|
|
easing.type: Easing.OutBack
|
2020-03-12 03:53:55 +11:00
|
|
|
duration: theme.animationDuration * 1.5
|
2019-12-19 08:00:02 +11:00
|
|
|
}
|
2020-03-28 22:18:00 +11:00
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToLastPage
|
|
|
|
onActivated: showPrevious()
|
|
|
|
}
|
2019-12-19 08:00:02 +11:00
|
|
|
}
|