MauiKit Controls

SplitViewItem.qml
1// Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
2// Copyright 2018-2020 Nitrux Latinoamericana S.C.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6
7import QtQuick
8import QtQuick.Controls
9import QtQml.Models
10import Qt5Compat.GraphicalEffects
11
12import org.mauikit.controls 1.3 as Maui
13
14/**
15 * @inherit QtQuick.Controls.Pane
16 * @brief An item to be used as a view container for the MauiKit SplitView.
17 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-pane.html">This controls inherits from QQC2 Pane, to checkout its inherited properties refer to the Qt Docs.</a>
18 * This is the preferred control to use when adding a new view into the SplitView, since it follows the Maui Style HIG.
19 * @see SplitView
20 *
21 * @note When this element is being resized by the SplitView handle, and reaches the minimum width, an action to close the view is then suggested and triggered if the pressed event of the handle is released at that minimum width.
22 */
23Pane
24{
25 id: control
26
27 Maui.Theme.colorSet: Maui.Theme.Window
28 Maui.Theme.inherit: false
29
30 /**
31 * @brief By default the children content of this item needs to be positioned manually.
32 * @property list<QtObject> SplitViewItem::content
33 */
34 default property alias content: _container.data
35
36 /**
37 * @brief The index of this view in the SplitView control.
38 */
39 readonly property int splitIndex : ObjectModel.index
40
41 /**
42 * @brief The minimum width of this view when resizing the SplitView.
43 * By default this is set to a fixed value of `200`.
44 */
45 property int minimumWidth : 200
46
47 /**
48 * @brief The minimum height of this view when resizing the SplitView.
49 * By default this is set to a fixed value of `100`.
50 */
51 property int minimumHeight : 100
52
53 /**
54 * @brief Whether the style of this view will be more compact. A compact style has not border corners or styling.
55 * While a non-compact mode means there is more than on view in the parent SplitView and the views will have rounded corners.
56 * This is `true` for mobile devices and one there is a single item in the SplitView.
57 */
58 readonly property bool compact : Maui.Handy.isMobile || SplitView.view.count === 1
59
60 SplitView.fillHeight: true
61 SplitView.fillWidth: true
62
63 SplitView.preferredHeight: SplitView.view.orientation === Qt.Vertical ? SplitView.view.height / (SplitView.view.count) : SplitView.view.height
64 SplitView.minimumHeight: SplitView.view.orientation === Qt.Vertical ? minimumHeight : 0
66 SplitView.preferredWidth: SplitView.view.orientation === Qt.Horizontal ? SplitView.view.width / (SplitView.view.count) : SplitView.view.width
67 SplitView.minimumWidth: SplitView.view.orientation === Qt.Horizontal ? minimumWidth : 0
68
69 clip: SplitView.view.orientation === Qt.Vertical && SplitView.view.count === 2 && splitIndex > 0
70
71 padding: compact ? 0 : Maui.Style.contentMargins
72 Behavior on padding
73 {
74 NumberAnimation
75 {
76 duration: Maui.Style.units.shortDuration
77 easing.type: Easing.InQuad
78 }
79 }
80
81
82 contentItem: Item
83 {
84 Item
85 {
86 id: _container
87 anchors.fill: parent
88 }
89
90 Loader
91 {
92 asynchronous: true
93 anchors.fill: parent
94 active: control.SplitView.view.resizing
95 visible: active
96 sourceComponent: Rectangle
97 {
98 color: Maui.Theme.backgroundColor
99 opacity: (control.minimumWidth) / control.width
100 }
101 }
102
103 Loader
104 {
105 asynchronous: true
106 anchors.bottom: parent.bottom
107 anchors.left: parent.left
108 anchors.right: parent.right
109 height: 2
110 active: control.SplitView.view.currentIndex === splitIndex && control.SplitView.view.count > 1
111 visible: active
112 sourceComponent: Rectangle
113 {
114 color: Maui.Theme.highlightColor
115 }
116 }
117
118 Loader
119 {
120 asynchronous: true
121 anchors.centerIn: parent
122 active: control.SplitView.view.resizing && control.width < control.minimumWidth + 60
123 visible: active
124 sourceComponent: Maui.Chip
125 {
126 opacity: (control.minimumWidth) / control.width
127
128 Maui.Theme.backgroundColor: Maui.Theme.negativeTextColor
129 label.text: i18nd("mauikit", "Close Split")
130 }
131 }
132
133 Loader
134 {
135 asynchronous: true
136 anchors.centerIn: parent
137 active: control.SplitView.view.resizing && control.height < control.minimumHeight + 60
138 visible: active
139 sourceComponent: Maui.Chip
140 {
141 opacity: (control.minimumHeight) / control.height
142
143 Maui.Theme.backgroundColor: Maui.Theme.negativeTextColor
144 label.text: i18nd("mauikit", "Close Split")
145 }
146 }
147
148 MouseArea
149 {
150 anchors.fill: parent
151 propagateComposedEvents: true
152 preventStealing: false
153 cursorShape: undefined
154
155 onPressed: (mouse) =>
156 {
157 control.SplitView.view.currentIndex = control.splitIndex
158 mouse.accepted = false
159 }
160 }
161
162 layer.enabled: !control.compact
163 layer.smooth: true
164 layer.effect: OpacityMask
165 {
166 maskSource: Rectangle
167 {
168 width: _container.width
169 height: _container.height
170 radius: Maui.Style.radiusV
171 }
172 }
173 }
174
175 Connections
176 {
177 target: control.SplitView.view
178 function onResizingChanged()
179 {
180 if(control.width === control.minimumWidth && !control.SplitView.view.resizing)
181 {
182 control.SplitView.view.closeSplit(control.splitIndex)
183 }
184
185 if(control.height === control.minimumHeight && !control.SplitView.view.resizing)
186 {
187 control.SplitView.view.closeSplit(control.splitIndex)
188 }
189 }
190 }
191
192 /**
193 * @brief Forces to focus this item in the SplitView, and marks it as the current view.
194 */
195 function focusSplitItem()
196 {
197 control.SplitView.view.currentIndex = control.splitIndex
198 }
199}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.