MauiKit Controls

SplitView.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
9
10import org.mauikit.controls 1.3 as Maui
11
12/**
13 * @inherit QtQuick.Controls.SplitView
14 * @brief An extension to the QQC2 SplitView control, adding some extra functionality.
15 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-splitview.html">This controls inherits from QQC2 SplitView, to checkout its inherited properties refer to the Qt Docs.</a>
16 * This control add a quick way to add split views and remove them.
17 * @see addSplit
18 * @see closeSplit
19 *
20 * @image html Misc/splitview.png
21 *
22 * @code
23 * Maui.SplitView
24 * {
25 * anchors.fill: parent
26 *
27 * Maui.SplitViewItem
28 * {
29 * Rectangle
30 * {
31 * color: "orange"
32 * anchors.fill: parent
33 * }
34 * }
35 *
36 * Maui.SplitViewItem
37 * {
38 * Rectangle
39 * {
40 * color: "yellow"
41 * anchors.fill: parent
42 * }
43 * }
44 * }
45 * @endcode
46 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/SplitView.qml">You can find a more complete example at this link.</a>
47 */
48SplitView
49{
50 id: control
51
52 clip: false
53
54 onCurrentItemChanged:
55 {
56 currentItem.forceActiveFocus()
57 }
58
59 /**
60 * @brief Forces to close the split view at a given index.
61 * If there is onyl one view at the time, then this method does nothing, in order to keep the control with at least one view.
62 * @note This function calls to the SplitView `removeItem` function.
63 * @param index the index of view to be closed
64 */
65 function closeSplit(index)
66 {
67 if(control.count === 1)
68 {
69 return // do not close aall
70 }
71
72 control.removeItem(control.takeItem(index))
73 }
74
75 /**
76 * @brief Adds a QQC2 Component as a view to the control.
77 * @param component The QQC2 Component wrapping the view to be added. Consider using a MauiKit SplitViewItem control as the view root element.
78 * @param properties an optional map of properties to be applied to the created view component
79 * @return the newly created object view.
80 */
81 function addSplit(component, properties)
82 {
83 const object = component.createObject(control.contentModel, properties);
84
85 control.addItem(object)
86 control.currentIndex = Math.max(control.count -1, 0)
87
88 object.forceActiveFocus()
89
90 return object
91 }
92}
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.