2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-06-06 00:36:08 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-06-13 02:48:11 +03:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.5
|
2021-06-13 03:48:22 +03:00
|
|
|
import QtQuick.Layouts 1.12
|
2021-06-06 00:36:08 +03:00
|
|
|
import im.nheko 1.0
|
|
|
|
|
|
|
|
Container {
|
|
|
|
//Component.onCompleted: {
|
|
|
|
// parent.width = Qt.binding(function() { return calculatedWidth; })
|
|
|
|
//}
|
|
|
|
|
|
|
|
id: container
|
|
|
|
|
|
|
|
property bool singlePageMode: width < 800
|
|
|
|
property int splitterGrabMargin: Nheko.paddingSmall
|
2021-12-07 01:38:39 +03:00
|
|
|
property alias pageIndex: view.currentIndex
|
2021-06-06 00:36:08 +03:00
|
|
|
property Component handle
|
2021-06-08 23:18:51 +03:00
|
|
|
property Component handleToucharea
|
|
|
|
|
2021-12-07 01:38:39 +03:00
|
|
|
onSinglePageModeChanged: if (!singlePageMode) pageIndex = 0
|
|
|
|
|
2021-06-08 23:18:51 +03:00
|
|
|
Component.onCompleted: {
|
|
|
|
for (var i = 0; i < count - 1; i++) {
|
|
|
|
let handle_ = handle.createObject(contentChildren[i]);
|
|
|
|
let split_ = handleToucharea.createObject(contentChildren[i]);
|
|
|
|
contentChildren[i].width = Qt.binding(function() {
|
|
|
|
return split_.calculatedWidth;
|
|
|
|
});
|
|
|
|
contentChildren[i].splitterWidth = Qt.binding(function() {
|
|
|
|
return handle_.width;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
contentChildren[count - 1].width = Qt.binding(function() {
|
|
|
|
if (container.singlePageMode) {
|
|
|
|
return container.width;
|
|
|
|
} else {
|
|
|
|
var w = container.width;
|
|
|
|
for (var i = 0; i < count - 1; i++) {
|
|
|
|
if (contentChildren[i].width)
|
|
|
|
w = w - contentChildren[i].width;
|
|
|
|
|
|
|
|
}
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
contentChildren[count - 1].splitterWidth = 0;
|
|
|
|
for (var i = 0; i < count; i++) {
|
|
|
|
contentChildren[i].height = Qt.binding(function() {
|
|
|
|
return container.height;
|
|
|
|
});
|
|
|
|
contentChildren[i].children[0].height = Qt.binding(function() {
|
|
|
|
return container.height;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-06-06 00:36:08 +03:00
|
|
|
|
|
|
|
handle: Rectangle {
|
|
|
|
z: 3
|
|
|
|
color: Nheko.theme.separator
|
|
|
|
height: container.height
|
|
|
|
width: visible ? 1 : 0
|
|
|
|
anchors.right: parent.right
|
|
|
|
}
|
|
|
|
|
|
|
|
handleToucharea: Item {
|
|
|
|
id: splitter
|
|
|
|
|
|
|
|
property int minimumWidth: parent.minimumWidth
|
|
|
|
property int maximumWidth: parent.maximumWidth
|
|
|
|
property int collapsedWidth: parent.collapsedWidth
|
|
|
|
property bool collapsible: parent.collapsible
|
|
|
|
property int calculatedWidth: {
|
|
|
|
if (!visible)
|
|
|
|
return 0;
|
|
|
|
else if (container.singlePageMode)
|
|
|
|
return container.width;
|
|
|
|
else
|
|
|
|
return (collapsible && x < minimumWidth) ? collapsedWidth : x;
|
|
|
|
}
|
|
|
|
|
|
|
|
enabled: !container.singlePageMode
|
|
|
|
height: container.height
|
|
|
|
width: 1
|
|
|
|
x: parent.preferredWidth
|
|
|
|
z: 3
|
|
|
|
|
2021-06-13 02:48:11 +03:00
|
|
|
CursorShape {
|
|
|
|
height: parent.height
|
|
|
|
width: container.splitterGrabMargin * 2
|
|
|
|
x: -container.splitterGrabMargin
|
|
|
|
cursorShape: Qt.SizeHorCursor
|
|
|
|
}
|
|
|
|
|
2021-06-06 00:36:08 +03:00
|
|
|
DragHandler {
|
|
|
|
id: dragHandler
|
|
|
|
|
|
|
|
enabled: !container.singlePageMode
|
|
|
|
xAxis.enabled: true
|
|
|
|
yAxis.enabled: false
|
|
|
|
xAxis.minimum: splitter.minimumWidth - 1
|
|
|
|
xAxis.maximum: splitter.maximumWidth
|
|
|
|
margin: container.splitterGrabMargin
|
|
|
|
grabPermissions: PointerHandler.CanTakeOverFromAnything | PointerHandler.ApprovesTakeOverByHandlersOfSameType
|
|
|
|
onActiveChanged: {
|
2021-12-11 22:47:41 +03:00
|
|
|
if (!active) {
|
|
|
|
splitter.x = splitter.calculatedWidth;
|
|
|
|
splitter.parent.preferredWidth = splitter.calculatedWidth;
|
|
|
|
}
|
2021-06-06 00:36:08 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HoverHandler {
|
|
|
|
enabled: !container.singlePageMode
|
|
|
|
margin: container.splitterGrabMargin
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: ListView {
|
|
|
|
id: view
|
|
|
|
|
|
|
|
model: container.contentModel
|
|
|
|
snapMode: ListView.SnapOneItem
|
|
|
|
orientation: ListView.Horizontal
|
|
|
|
highlightRangeMode: ListView.StrictlyEnforceRange
|
2021-12-07 01:38:39 +03:00
|
|
|
interactive: singlePageMode
|
2023-02-06 15:56:23 +03:00
|
|
|
highlightMoveDuration: (container.singlePageMode && !Settings.reducedMotion) ? 200 : 0
|
2021-06-06 00:36:08 +03:00
|
|
|
currentIndex: container.singlePageMode ? container.pageIndex : 0
|
2022-03-27 22:23:40 +03:00
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
2021-06-06 00:36:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|