Debian Codegraph @

resources/qml/components/AdaptiveLayout.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import QtQuick
6 import QtQuick.Controls
7 import im.nheko
8
9 Container {
10 //Component.onCompleted: {
11 // parent.width = Qt.binding(function() { return calculatedWidth; })
12 //}
13
14 id: container
15
16 property bool singlePageMode: width < 800
17 property int splitterGrabMargin: Nheko.paddingSmall
18 property alias pageIndex: view.currentIndex
19 property Component handle
20 property Component handleToucharea
21
22 onSinglePageModeChanged: if (!singlePageMode) pageIndex = 0
23
24 Component.onCompleted: {
25 for (var i = 0; i < count - 1; i++) {
26 let handle_ = handle.createObject(contentChildren[i]);
27 let split_ = handleToucharea.createObject(contentChildren[i]);
28 contentChildren[i].width = Qt.binding(function() {
29 return split_.calculatedWidth;
30 });
31 contentChildren[i].splitterWidth = Qt.binding(function() {
32 return handle_.width;
33 });
34 }
35 contentChildren[count - 1].width = Qt.binding(function() {
36 if (container.singlePageMode) {
37 return container.width;
38 } else {
39 var w = container.width;
40 for (var i = 0; i < count - 1; i++) {
41 if (contentChildren[i].width)
42 w = w - contentChildren[i].width;
43
44 }
45 return w;
46 }
47 });
48 contentChildren[count - 1].splitterWidth = 0;
49 for (var i = 0; i < count; i++) {
50 contentChildren[i].height = Qt.binding(function() {
51 return container.height;
52 });
53 contentChildren[i].children[0].height = Qt.binding(function() {
54 return container.height;
55 });
56 }
57 }
58
59 handle: Rectangle {
60 z: 3
61 color: Nheko.theme.separator
62 height: container.height
63 width: visible ? 1 : 0
64 anchors.right: parent.right
65 }
66
67 handleToucharea: Item {
68 id: splitter
69
70 property int minimumWidth: parent.minimumWidth
71 property int maximumWidth: parent.maximumWidth
72 property int collapsedWidth: parent.collapsedWidth
73 property bool collapsible: parent.collapsible
74 property int calculatedWidth: {
75 if (!visible)
76 return 0;
77 else if (container.singlePageMode)
78 return container.width;
79 else
80 return (collapsible && x < minimumWidth) ? collapsedWidth : x;
81 }
82
83 enabled: !container.singlePageMode
84 height: container.height
85 width: 1
86 x: parent.preferredWidth
87 z: 3
88
89 NhekoCursorShape {
90 height: parent.height
91 width: container.splitterGrabMargin * 2
92 x: -container.splitterGrabMargin
93 cursorShape: Qt.SizeHorCursor
94 }
95
96 DragHandler {
97 id: dragHandler
98
99 enabled: !container.singlePageMode
100 xAxis.enabled: true
101 yAxis.enabled: false
102 xAxis.minimum: splitter.minimumWidth - 1
103 xAxis.maximum: splitter.maximumWidth
104 margin: container.splitterGrabMargin
105 grabPermissions: PointerHandler.CanTakeOverFromAnything | PointerHandler.ApprovesTakeOverByHandlersOfSameType
106 onActiveChanged: {
107 if (!active) {
108 splitter.x = splitter.calculatedWidth;
109 splitter.parent.preferredWidth = splitter.calculatedWidth;
110 }
111
112 }
113 }
114
115 HoverHandler {
116 enabled: !container.singlePageMode
117 margin: container.splitterGrabMargin
118 }
119
120 }
121
122 contentItem: ListView {
123 id: view
124
125 model: container.contentModel
126 snapMode: ListView.SnapOneItem
127 orientation: ListView.Horizontal
128 highlightRangeMode: ListView.StrictlyEnforceRange
129 interactive: !Settings.disableSwipe && singlePageMode
130 highlightMoveDuration: (container.singlePageMode && !Settings.reducedMotion) ? 200 : 0
131 currentIndex: container.singlePageMode ? container.pageIndex : 0
132 boundsBehavior: Flickable.StopAtBounds
133 }
134
135 }