MauiKit Controls

SideBarView.qml
1import QtQuick
2import QtQuick.Controls
3
4import org.mauikit.controls 1.3 as Maui
5import "private" as Private
6
7/**
8 * @brief A view with a collapsible sidebar.
9 *
10 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-item.html">This controls inherits from QQC2 Item, to checkout its inherited properties refer to the Qt Docs.</a>
11 *
12 * The SideBarView is a convenient way for organizing the application contents into view alongside with a side-bar, which can be resized, collased, hidden and tweaked further. This control adapts to small screen spaces.
13 *
14 * @image html SideBarView/sidebar_empty.png
15 *
16 * @section sections Sections
17 * The SideBarView is divided into two sections, the sidebar container and the main contents area.
18 *
19 * @subsection sidebar SideBar
20 * The sidebar area can contain any number children items, and its positioning must be handled manually, either by anchoring or using the size and coordinates properties - anchoring to fill its parent is the best way to go, since the sidebar container can changed its size and positioning.
21 *
22 * Once a child item has been set, other properties can be visited, such as setting the sidebar preferred and minimum width, or deciding if the sidebar will be resize-able or not. Those properties can be accessed via the alias property of the sidebar.
23 * @see sideBar
24 *
25 * The sidebar can be hidden at the application startup, to tweak this behaviour the auto hide properties can be set accordingly.
26 * The sidebar can also be collapsed, and this behavior can be fine-tuned, by either deciding if when collapsing the sidebar should stay visible or not.
27 *
28 * Tweaking the look of the sidebar can also be achieved by changing its background and padding properties. Those all properties are accessible via the alias property `sideBar` - and a few more methods for closing or opening the sidebar.
29 * @see SideBar
30 *
31 * @image html SideBarView/sidebar_collapsed.png "The sidebar is collapsed and expanded, shifting the main area content"
32 *
33 * @subsection maincontent Content
34 * The position of the main content of the SideBarView has to be done by the child item.
35 * The default behaviour of the main content is be to shifted/moved when the sidebar being collapsed is expanded.
36 *
37 * @code
38 * Maui.SideBarView
39 * {
40 * id: _sideBar
41 * anchors.fill: parent
42 *
43 * sideBarContent: Maui.Page
44 * {
45 * Maui.Theme.colorSet: Maui.Theme.Window
46 * anchors.fill: parent
47 *
48 * headBar.leftContent: Maui.ToolButtonMenu
49 * {
50 * icon.name: "application-menu"
51 * MenuItem
52 * {
53 * text: "About"
54 * icon.name: "info-dialog"
55 * onTriggered: root.about()
56 * }
57 * }
58 *
59 * Maui.Holder
60 * {
61 * anchors.fill: parent
62 * title: "SideBar"
63 * body: "Collapsable."
64 * emoji: "folder"
65 * }
66 * }
67 *
68 * Maui.Page
69 * {
70 * anchors.fill: parent
71 * Maui.Controls.showCSD: true
72 *
73 * headBar.leftContent: ToolButton
74 * {
75 * icon.name: _sideBar.sideBar.visible ? "sidebar-collapse" : "sidebar-expand"
76 * onClicked: _sideBar.sideBar.toggle()
77 * }
78 *
79 * Maui.Holder
80 * {
81 * anchors.fill: parent
82 * title: "Page"
83 * body: "Page main content."
84 * emoji: "application-x-addon-symbolic"
85 * }
86 * }
87 * }
88 * @endcode
89 *
90 * @section notes Notes
91 *
92 * The width of the sidebar section will always be restrained to a maximum value less than the window width - by reserving a sane margin to be able to close the sidebar by clicking/pressing outside of it.
93 *
94 * To place an item in the sidebar, use the exposed alias property.
95 * @see sideBarContent
96 *
97 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/SideBarView.qml">You can find a more complete example at this link.</a>
98 *
99 */
100Item
101{
102 id: control
103
104 /**
105 * @brief
106 * All child items declared will become part of the main area section.
107 * @property list<QtObject> SideBarView::content
108 */
109 default property alias content : _content.data
111 /**
112 * @brief Convenient property to easily add items to the sidebar section.
113 * @property list<QtObject> SideBarView::sideBarContent
114 */
115 property alias sideBarContent: _sideBar.content
116
117 /**
118 * @brief This is an alias exposed to access all the sidebar section properties.
119 * To know more about the available properties visit the control documentation.
120 * @see SideBar
121 *
122 * @code
123 * SideBarView
124 * {
125 * sideBar.collapsed: width < 800
126 * sideBar.resizeable: false
127 * sideBar.autoHide: true
128 * }
129 * @endcode
130 */
131 readonly property alias sideBar : _sideBar
132
133 Private.SideBar
134 {
135 id: _sideBar
136 height: parent.height
137 collapsed: control.width < (preferredWidth * 2.5)
138 sideBarView: control
139 }
140
141 Item
142 {
143 anchors.fill: parent
144 clip: true
145 transform: Translate
146 {
147 x: control.sideBar.collapsed ? control.sideBar.position * (control.sideBar.width) : 0
148 }
149
150 anchors.leftMargin: control.sideBar.collapsed ? 0 : control.sideBar.width * control.sideBar.position
151
152 Item
153 {
154 id: _content
155 anchors.fill: parent
156 }
157
158 Loader
159 {
160 anchors.fill: parent
161 active: _sideBar.collapsed && _sideBar.position === 1
162 // asynchronous: true
163
164 sourceComponent: MouseArea
165 {
166 onClicked: _sideBar.close()
167
168 Rectangle
169 {
170 anchors.fill: parent
171 color: "#333"
172 opacity : visible ? 0.5 : 0
173
174 Behavior on opacity
175 {
176 NumberAnimation
177 {
178 duration: 500
179 easing.type: Easing.InOutQuad
180 }
181 }
182 }
183 }
184 }
185 }
186}
187
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.