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
|
|
|
// List of previously loaded [componentUrl, {properties}]
|
|
|
|
property var history: []
|
|
|
|
property int historyLength: 20
|
|
|
|
|
2020-09-14 05:46:58 +10:00
|
|
|
readonly property alias appearAnimation: appearAnimation
|
|
|
|
|
2020-09-04 07:59:48 +10:00
|
|
|
signal aboutToRecycle()
|
2020-09-03 05:25:02 +10:00
|
|
|
signal recycled()
|
2020-07-12 14:25:57 +10:00
|
|
|
signal previousShown(string componentUrl, var properties)
|
2019-12-19 08:00:02 +11:00
|
|
|
|
2020-09-04 07:33:19 +10:00
|
|
|
function show(componentUrl, properties={}) {
|
2019-12-19 08:00:02 +11:00
|
|
|
history.unshift([componentUrl, properties])
|
|
|
|
if (history.length > historyLength) history.pop()
|
|
|
|
|
2020-09-03 05:07:10 +10:00
|
|
|
const recycle =
|
|
|
|
window.uiState.page === componentUrl &&
|
|
|
|
componentUrl === "Pages/Chat/Chat.qml" &&
|
|
|
|
item
|
|
|
|
|
|
|
|
if (recycle) {
|
2020-09-04 07:59:48 +10:00
|
|
|
aboutToRecycle()
|
|
|
|
|
2020-09-03 05:07:10 +10:00
|
|
|
for (const [prop, value] of Object.entries(properties))
|
|
|
|
item[prop] = value
|
2020-09-03 05:25:02 +10:00
|
|
|
|
|
|
|
recycled()
|
2020-09-03 05:07:10 +10:00
|
|
|
} else {
|
|
|
|
pageLoader.setSource(componentUrl, properties)
|
|
|
|
window.uiState.page = componentUrl
|
|
|
|
}
|
2019-12-19 08:00:02 +11:00
|
|
|
|
|
|
|
window.uiState.pageProperties = properties
|
|
|
|
window.uiStateChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
function showRoom(userId, roomId) {
|
2020-09-14 02:47:25 +10:00
|
|
|
show("Pages/Chat/Chat.qml", {userRoomId: [userId, roomId]})
|
2019-12-19 08:00:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
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]
|
2020-09-04 07:33:19 +10:00
|
|
|
show(componentUrl, properties)
|
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()
|
2020-09-04 07:59:48 +10:00
|
|
|
if (mainPane.collapse) mainPane.close()
|
2019-12-19 08:00:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
clip: appearAnimation.running
|
|
|
|
|
2020-09-04 00:49:15 +10:00
|
|
|
onLoaded: { takeFocus(); appearAnimation.restart() }
|
2020-09-04 07:59:48 +10:00
|
|
|
onRecycled: { takeFocus(); appearAnimation.restart() }
|
2020-07-12 14:25:57 +10:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
if (! py.startupAnyAccountsSaved) {
|
2020-09-05 00:51:33 +10:00
|
|
|
pageLoader.show("Pages/AddAccount/AddAccount.qml")
|
2020-07-12 14:25:57 +10:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-04 07:33:19 +10:00
|
|
|
pageLoader.show(window.uiState.page, window.uiState.pageProperties)
|
2020-07-12 14:25:57 +10:00
|
|
|
}
|
|
|
|
|
2019-12-19 08:00:02 +11:00
|
|
|
HNumberAnimation {
|
|
|
|
id: appearAnimation
|
|
|
|
target: pageLoader.item
|
|
|
|
property: "x"
|
2020-09-04 00:49:15 +10:00
|
|
|
from: -pageLoader.width
|
2019-12-19 08:00:02 +11:00
|
|
|
to: 0
|
2020-09-04 00:49:15 +10:00
|
|
|
easing.type: Easing.OutCirc
|
|
|
|
factor: 2
|
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
|
|
|
}
|