1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-03-28 14:56:19 +01:00
jami-client-qt/src/app/commoncomponents/ListSelectionView.qml
Sébastien Blin 84150e8977 misc: bump copyright to 2024
Change-Id: I8d5f968fbedbc884c91416246049a0ef4cd652eb
2024-01-03 09:54:49 -05:00

88 lines
3 KiB
QML

/*
* Copyright (C) 2024 Savoir-faire Linux Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
DualPaneView {
id: viewNode
property bool hideRightPaneInSinglePaneMode : false
Component.onCompleted: {
if (hideRightPaneInSinglePaneMode) return
onIndexChanged.connect(function() {
if (hasValidSelection) {
if (selectionFallback && isSinglePane)
rightPaneItem.parent = leftPane
return
}
if (!isSinglePane) dismiss()
else isSinglePaneChangedHandler()
})
}
// True if we should dismiss to the left pane if in single pane mode.
// Also causes selection of a default index (0) in dual pane mode.
property bool selectionFallback: false
// When this property is set, the view updates its display to show the
// corresponding item if `hasValidSelection` has no override.
property int index: -1
function selectIndex(index) { viewNode.index = index }
// Override this predicate if needed.
property bool hasValidSelection: viewNode.index >= -1
onHasValidSelectionChanged: isSinglePaneChangedHandler()
// Override BaseView.dismiss with some selection logic.
function dismiss() {
if (isSinglePane) {
if (!selectionFallback) viewCoordinator.dismiss(objectName)
else if (isSinglePane && leftPane.children.length > 1) {
rightPaneItem.parent = null
leftPaneItem.deselect()
}
} else viewCoordinator.dismiss(objectName)
}
onPresented: isSinglePaneChangedHandler()
onDismissed: {
if (leftPaneItem) {
leftPaneItem.indexSelected.disconnect(selectIndex)
leftPaneItem.deselect()
}
}
onLeftPaneItemChanged: {
if (leftPaneItem) leftPaneItem.indexSelected.connect(selectIndex)
}
isSinglePaneChangedHandler: () => {
if (hideRightPaneInSinglePaneMode) return
// When transitioning from split to single pane, we need to move
// the right pane item to left stack view if it has a valid index.
if (isSinglePane) {
if (hasValidSelection) {
rightPaneItem.parent = leftPane
}
} else {
rightPaneItem.parent = rightPane
// We may need a default selection of item 0 here.
if (!hasValidSelection && selectionFallback) leftPaneItem.select(0)
}
}
}