2020-09-24 09:57:54 +10:00
|
|
|
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-14 08:54:32 +11:00
|
|
|
import QtQuick 2.12
|
2019-12-14 08:19:47 +11:00
|
|
|
import QtQuick.Controls 2.12
|
2020-03-28 22:18:00 +11:00
|
|
|
import "../ShortcutBundles"
|
2019-12-14 08:19:47 +11:00
|
|
|
|
|
|
|
SwipeView {
|
2020-03-28 22:18:00 +11:00
|
|
|
id: swipeView
|
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
enum Move { ToPrevious, ToNext }
|
2019-12-14 08:19:47 +11:00
|
|
|
|
|
|
|
property string saveName: ""
|
|
|
|
property var saveId: "ALL"
|
|
|
|
property var saveProperties: ["currentIndex"]
|
|
|
|
|
2019-12-14 08:54:32 +11:00
|
|
|
// Prevent onCurrentIndexChanged from running before Component.onCompleted
|
|
|
|
property bool saveEnabled: false
|
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
property int previousIndex: 0
|
2019-12-14 08:19:47 +11:00
|
|
|
property int defaultIndex: 0
|
2020-04-27 04:20:45 +10:00
|
|
|
property int lastMove: HSwipeView.Move.ToNext
|
2019-12-14 08:19:47 +11:00
|
|
|
property bool changed: currentIndex !== defaultIndex
|
|
|
|
|
|
|
|
function reset() { setCurrentIndex(defaultIndex) }
|
2020-03-28 22:18:00 +11:00
|
|
|
|
2020-04-28 12:10:10 +10:00
|
|
|
function incrementWrapIndex() {
|
|
|
|
currentIndex === count - 1 ?
|
|
|
|
setCurrentIndex(0) :
|
|
|
|
incrementCurrentIndex()
|
|
|
|
}
|
|
|
|
|
|
|
|
function decrementWrapIndex() {
|
|
|
|
currentIndex === 0 ?
|
|
|
|
setCurrentIndex(count - 1) :
|
|
|
|
decrementCurrentIndex()
|
|
|
|
}
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
Component.onCompleted: if (! changed) {
|
|
|
|
setCurrentIndex(window.getState(this, "currentIndex", defaultIndex))
|
|
|
|
saveEnabled = true
|
|
|
|
}
|
|
|
|
|
|
|
|
onCurrentIndexChanged: {
|
|
|
|
if (saveEnabled) window.saveState(this)
|
|
|
|
|
|
|
|
if (currentIndex < previousIndex) lastMove = HSwipeView.Move.ToPrevious
|
|
|
|
if (currentIndex > previousIndex) lastMove = HSwipeView.Move.ToNext
|
|
|
|
|
|
|
|
previousIndex = currentIndex
|
|
|
|
}
|
|
|
|
|
2020-03-28 22:18:00 +11:00
|
|
|
TabShortcuts {
|
|
|
|
container: swipeView
|
|
|
|
}
|
2019-12-14 08:19:47 +11:00
|
|
|
}
|